<?php
//namespace Module\Index;

use Core\View;
use Core\Response;
use Core\Request;
use Core\DB;
use Libs\Fun;

class _index
{
	public function initc(){}
    
    public function index()
    {
        View::display('index');
    }

    public function dbHostsName()
    {
        $db = new DB();
        $hosts = $db->getHostInfo();
        Response::success(array_keys($hosts));
    }

    public function dbDatabase()
    {
        $host = Request::Post('host_name');
        $db = new DB();
        $dbList = $db->getDatabaseList($host);

        Response::success($dbList);
    }

    public function dbTables()
    {
        $host = Request::Post('host_name');
        $dbname = Request::Post('db_name');
        $db = new DB();
        $dbList = $db->getTableList($host, $dbname);
        sort($dbList);

        Response::success($dbList);
    }

    public function dbFields()
    {
        $host = Request::Post('host_name');
        $dbname = Request::Post('db_name');
        $table = Request::Post('table_name');

        $db = new DB();
        $fieldList = $db->getFieldList($host, $dbname, $table);
        Fun::sort2DArray($fieldList, 'COLUMN_NAME');

        Response::success($fieldList);
    }
}